<?php 
$version_info = explode("*",get_latest_version("course_description",$cid));
if ($id == "default") $query_cd_comments = sprintf("SELECT * FROM comments WHERE cid='%s' AND tableName='%s' AND rid='%s'", $cid, "course_description", $version_info[0]);
else $query_cd_comments = sprintf("SELECT * FROM comments WHERE cid='%s' AND tableName='%s' AND rid='%s'", $cid, "course_description", $row_cd['id']);
$cd_comments = mysql_query($query_cd_comments, $connection) or die(mysql_error());
$row_cd_comments = mysql_fetch_assoc($cd_comments);
$totalRows_cd_comments = mysql_num_rows($cd_comments);
if (($section != "comments") && ($id != "default")) {
	if (($row_cd_latest['vid'] == $row_cd['vid']) && ($totalRows_cd_comments > 0)) echo "<div class='error_msg'>Changes are needed to the course description.</div>";
	if (($totalRows_cd_comments > 0) && ($modal_window == "false")) echo "<div class='info'><a href='#comments'>Click here</a> to view the comments from the Instructional Designer.</div>";
	}

/*
$query_cd_latest = "SELECT * FROM course_description WHERE cid='$cid' ORDER BY vid DESC"; 
$cd_latest = mysql_query($query_cd_latest, $connection) or die(mysql_error());
$row_cd_latest = mysql_fetch_assoc($cd_latest);
$totalRows_cd_latest = mysql_num_rows($cd_latest);
*/

if (($section == "comments") || ($section == "view_comments")) { ?>
<div id="comment-preview">
<h2><?php echo $row_courses['jiu_course_id']; ?> Course Description <?php if (($id != "default") && ($row_user['userLevel'] <= "2")) echo " (Version ".$row_cd['vid'].")"; ?></h2>
<h3>This course introduces students to...</h3>
<?php echo $row_cd['cd_desc1']; ?>
<h3>Students will examine a wide range of topics including...</h3>
<?php echo $row_cd['cd_desc2']; ?>
</div>

<?php } // END if (($section == "comments") || ($section == "view_comments"))
else 
{

	if ($totalRows_cd == 0) { echo "<a name=\"cd\"></a><h2>Course Description</h2><div class='error_msg'>A Course Description has not been entered."; if ($row_user['userLevel'] == "3") echo " <a href='index.php?section=cd&action=add&cid=".$cid."'>Add the Course Description</a>?"; echo "</div>"; } 
	else {
	

?>
<a name="cd"></a><h2>Course Description <?php if (($id != "default") && ($row_user['userLevel'] <= "2")) echo " (Version ".$row_cd['vid'].")"; ?></h2>
<table class="dataTable">
  <tr>
    <th colspan="5">This course introduces students to...</th>
  </tr>
  <?php if (($section != "proposal_reveiw") && ($id == "default") && ($modal_window == "false") && ($row_user['userLevel'] <= "2")) { ?>
  <tr>
  	<td <?php if ($section != "comments") echo 'colspan="5"'; ?>>
    <div class="stacked">
    <span class="icon"><img src="images/page_edit.png" align="absmiddle" border="0"></span><a id="modal_window_link" href="index.php?section=cd&amp;action=edit&amp;go=review&amp;view=proposal_detail&amp;cid=<?php echo $cid; ?>&amp;vid=<?php echo $row_cd['vid']; ?>&amp;id=<?php echo $row_cd['id']."&amp;modal_window=true"; ?>" title="Edit the Course Description">Edit</a>
    </div>
    </td>
  </tr>
  <?php } ?>
  <tr>
  	<td colspan="5"><?php echo $row_cd['cd_desc1']; ?></td>
  </tr>
  <tr>
    <th colspan="5">Students will examine a wide range of topics including...</th>
  </tr>
  <?php if (($section != "proposal_reveiw") && ($id == "default") && ($modal_window != "true") && ($row_user['userLevel'] <= "2")) { ?>
  <tr>
  	<td colspan="5">
    <span class="icon"><img src="images/page_edit.png" align="absmiddle" border="0"></span><a id="modal_window_link" href="index.php?section=cd&amp;action=edit&amp;go=review&amp;view=proposal_detail&amp;cid=<?php echo $cid; ?>&amp;vid=<?php echo $row_cd['vid']; ?>&amp;id=<?php echo $row_cd['id']."&amp;modal_window=true"; ?>" title="Edit the Course Description">Edit</a>
    </td>
  </tr>
  <?php } ?>
  <tr>
  	<td colspan="5"><?php echo $row_cd['cd_desc2']; ?></td>
  </tr>
<?php if (($modal_window == "false") && ($id == "default")) { ?>
<tr>
    <th width="20%"><?php if (($section != "proposal_reveiw") && ($id == "default") && ($modal_window != "true")) echo "ID / ReviewerComments?"; else echo "&nbsp;"; ?></th>
    <th width="20%"><?php if (($section != "proposal_reveiw") && ($id == "default") && ($modal_window != "true")) echo "Changes Needed?"; else echo "&nbsp;"; ?></th>
    <th width="20%"><?php if (($section == "view_proposal") && ($row_user['userLevel'] <= "2")) { if ($id == "default") echo "Latest "; echo "Version"; } ?></th>
    <th width="20%"><?php if (($section == "view_proposal") && ($row_user['userLevel'] <= "2")) echo "Other Versions"; else echo "&nbsp;"; ?></th>
    
    <th><?php if ($section == "proposal_reveiw") echo "Make Changes?"; else echo "&nbsp;"; ?></th>
    </tr>
    <tr>
    <td class="data"><?php if (($section != "proposal_reveiw") && ($id == "default") && ($modal_window != "true")) { echo view_comments('course_description','view_comments',$cid,$row_cd['id'],'proposal_detail',$totalRows_cd_comments,'modal');
	if ($row_user['userLevel'] <= "2") echo "<div class='stacked'><span class='icon'><img src='images/comment_add.png' align='absmiddle' border='0'></span><a id='modal_window_link' href='index.php?section=comments&amp;action=add&amp;go=default&amp;view=proposal_detail&amp;cid=".$cid."&amp;dbTable=course_description&amp;id=".$row_cd['id']."&amp;modal_window=true' title='Add a Comment About the Course Description'>Add Comment</a></div>"; } else echo "&nbsp;"; ?></td>
    <td class="data"><?php if (($section != "proposal_reveiw") && ($row_cd_comments['changes'] == "Y")) { echo "<span class='icon'><img src='images/error.png' align='absmiddle' border='0'></span>Yes"; if ($row_user['userLevel'] == "3") echo " - <a id='modal_window_link' href='index.php?section=cd&amp;action=add&amp;go=".$go."&amp;view=proposal_detail&amp;cid=".$cid."&amp;id=".$row_cd_comments['rid']."&amp;modal_window=true' title='Make Changes to the Course Description'>Make Changes</a>"; } elseif ($section != "proposal_reveiw") echo "<span class='icon'><img src='images/tick.png' align='absmiddle' border='0'></span>No"; ?></td>
    <td class="data"><?php if (($section == "view_proposal") && ($row_user['userLevel'] <= "2")) echo $row_cd['vid']; else echo "&nbsp;"; ?></td>
	<td class="data">
    <?php
	if (($section == "view_proposal") && ($row_user['userLevel'] <= "2")) echo previous_versions("course_description",$cid,$row_cd['vid'],$modal_window,$section,$action);
	} else echo "&nbsp;";
	?>
    </td>
    
    <td class="data"><?php if ($section == "proposal_reveiw") { ?><a href="index.php?section=cd&action=edit&go=review&cid=<?php echo $cid; ?>&vid=<?php echo $row_cd['vid']; ?>&id=<?php echo $row_cd['id']; ?>">Yes</a><?php } else echo "&nbsp;"; ?></td>
    </tr>
<?php } ?>
</table>
<?php echo top_link($section,$modal_window);  
if (($id != "default") && ($totalRows_comments > 0) && ($section != "comments") && ($section != "view_comments")) { ?>
<a name="comments"></a><h2>Instructional Designer Comments</h2>
<table class="dataTable">
<tr>
	<th width="10%" nowrap="nowrap">ID</th>
    <th>Comments</th>
    <th width="13%">Changes Needed?</th>
    <th width="13%">&nbsp;</th>
</tr>
<?php do { ?>
<tr>
	<td width="5%" nowrap="nowrap"><p><?php echo $row_id['firstName']." ".$row_id['lastName']; ?><p></td>
    <td class="data"><?php echo $row_comments['comment']; if (($row_user['userLevel'] <= "2") && ($modal_window == "false")) { ?><span class="icon"><img src="images/page_edit.png" align="absmiddle" border="0"></span><a href="index.php?section=comments&action=edit&dbTable=<?php echo $dbTable; ?>&cid=<?php echo $cid; ?>&id=<?php echo $row_comments['id']; ?>&amp;modal_window=<?php echo $modal_window; ?>">Edit</a><?php } ?></td>
    <td class="data">
	<?php if ($version_info[1] == $row_cd['vid']) echo changes_needed($row_comments['changes']); else echo "Version out of date." ?>
    </td>
    <td class="data">
	<?php if (($version_info[1] == $row_cd['vid']) && ($row_comments['changes'] == "Y"))  echo "<a href='index.php?section=cd&amp;action=edit&amp;go=".$go."&amp;view=proposal_detail&amp;cid=".$cid."&amp;id=".$row_comments['rid']."&amp;modal_window=".$modal_window."'>Make Changes</a>"; else echo "&nbsp;"; ?>
    </td>
</tr>
<?php if ($color == $color1) { $color = $color2; } else { $color = $color1; } ?>
<?php } while ($row_comments = mysql_fetch_assoc($comments)); ?>
</table>
<?php } //echo top_link($section,$modal_window); 
} ?>